package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.AdminClass;
import com.ruoyi.system.mapper.AdminClassMapper;
import com.ruoyi.system.service.IAdminClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 班级Service业务层处理
 * 
 * @author ruoyi
 * @date 2020-06-09
 */
@Service
public class AdminClassServiceImpl implements IAdminClassService 
{
    @Autowired
    private AdminClassMapper adminClassMapper;

    /**
     * 查询班级
     * 
     * @param classId 班级ID
     * @return 班级
     */
    @Override
    public AdminClass selectAdminClassById(Long classId)
    {
        return adminClassMapper.selectAdminClassById(classId);
    }

    /**
     * 查询班级列表
     * 
     * @param adminClass 班级
     * @return 班级
     */
    @Override
    public List<AdminClass> selectAdminClassList(AdminClass adminClass)
    {
        return adminClassMapper.selectAdminClassList(adminClass);
    }

    /**
     * 新增班级
     * 
     * @param adminClass 班级
     * @return 结果
     */
    @Override
    public int insertAdminClass(AdminClass adminClass)
    {
        adminClass.setCreateTime(DateUtils.getNowDate());
        return adminClassMapper.insertAdminClass(adminClass);
    }

    /**
     * 修改班级
     * 
     * @param adminClass 班级
     * @return 结果
     */
    @Override
    public int updateAdminClass(AdminClass adminClass)
    {
        adminClass.setUpdateTime(DateUtils.getNowDate());
        return adminClassMapper.updateAdminClass(adminClass);
    }

    /**
     * 删除班级对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteAdminClassByIds(String ids)
    {
        return adminClassMapper.deleteAdminClassByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除班级信息
     * 
     * @param classId 班级ID
     * @return 结果
     */
    @Override
    public int deleteAdminClassById(Long classId)
    {
        return adminClassMapper.deleteAdminClassById(classId);
    }
    
    /**
     * 班级状态修改
     * 
     * @param adminClass 班级信息
     * @return 结果
     */
    @Override
    public int changeStatus(AdminClass adminClass)
    {
        return adminClassMapper.updateAdminClass(adminClass);
    }

    @Override
    public List<AdminClass> selectClassByUserId (Long userId) {
      List<AdminClass> userClassList = adminClassMapper.selectClasssByUserId(userId);
      AdminClass adminClassquery = new AdminClass();
      adminClassquery.setStatus("0");
      List<AdminClass> adminClassList = adminClassMapper.selectAdminClassList(adminClassquery);
      for (AdminClass adminClass : adminClassList) {
        for (AdminClass userClass : userClassList) {
          if (userClass.getClassId().longValue() == adminClass.getClassId().longValue()) {
            adminClass.setFlag(true);
            break;
          }
        }
      }
      return adminClassList;
    }
}
